<?php

/**
 * This is the model class for table "xman_risk".
 *
 * The followings are the available columns in table 'xman_risk':
 * @property integer $risk_id
 * @property string $risk_name
 * @property string $risk_source
 * @property string $risk_probability
 * @property string $risk_impact
 * @property integer $risk_probability_value
 * @property integer $risk_impact_value
 * @property integer $risk_impact_cost
 * @property integer $risk_impact_schedule
 * @property integer $risk_impact_performance
 * @property string $risk_mitigation
 * @property string $risk_created_date
 * @property string $risk_updated_date
 * @property integer $risk_project_id
 * @property integer $risk_posted_by_user_id
 *
 * The followings are the available model relations:
 * @property Project $riskProject
 * @property User $riskPostedByUser
 */
class Risk extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Risk the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xman_risk';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('risk_source, risk_project_id, risk_posted_by_user_id', 'required'),
			array('risk_probability_value, risk_impact_value, risk_impact_cost, risk_impact_schedule, risk_impact_performance, risk_project_id, risk_posted_by_user_id', 'numerical', 'integerOnly'=>true),
			array('risk_name, risk_probability, risk_impact', 'length', 'max'=>50),
			array('risk_source', 'length', 'max'=>100),
			array('risk_mitigation', 'length', 'max'=>500),
			array('risk_created_date, risk_updated_date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('risk_id, risk_name, risk_source, risk_probability, risk_impact, risk_probability_value, risk_impact_value, risk_impact_cost, risk_impact_schedule, risk_impact_performance, risk_mitigation, risk_created_date, risk_updated_date, risk_project_id, risk_posted_by_user_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'riskProject' => array(self::BELONGS_TO, 'Project', 'risk_project_id'),
			'riskPostedByUser' => array(self::BELONGS_TO, 'User', 'risk_posted_by_user_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'risk_id' => 'Risk',
			'risk_name' => 'Risk Name',
			'risk_source' => 'Risk Source',
			'risk_probability' => 'Risk Probability',
			'risk_impact' => 'Risk Impact',
			'risk_probability_value' => 'Risk Probability Value',
			'risk_impact_value' => 'Risk Impact Value',
			'risk_impact_cost' => 'Risk Impact Cost',
			'risk_impact_schedule' => 'Risk Impact Schedule',
			'risk_impact_performance' => 'Risk Impact Performance',
			'risk_mitigation' => 'Risk Mitigation',
			'risk_created_date' => 'Risk Created Date',
			'risk_updated_date' => 'Risk Updated Date',
			'risk_project_id' => 'Risk Project',
			'risk_posted_by_user_id' => 'Risk Posted By User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('risk_id',$this->risk_id);
		$criteria->compare('risk_name',$this->risk_name,true);
		$criteria->compare('risk_source',$this->risk_source,true);
		$criteria->compare('risk_probability',$this->risk_probability,true);
		$criteria->compare('risk_impact',$this->risk_impact,true);
		$criteria->compare('risk_probability_value',$this->risk_probability_value);
		$criteria->compare('risk_impact_value',$this->risk_impact_value);
		$criteria->compare('risk_impact_cost',$this->risk_impact_cost);
		$criteria->compare('risk_impact_schedule',$this->risk_impact_schedule);
		$criteria->compare('risk_impact_performance',$this->risk_impact_performance);
		$criteria->compare('risk_mitigation',$this->risk_mitigation,true);
		$criteria->compare('risk_created_date',$this->risk_created_date,true);
		$criteria->compare('risk_updated_date',$this->risk_updated_date,true);
		$criteria->compare('risk_project_id',$this->risk_project_id);
		$criteria->compare('risk_posted_by_user_id',$this->risk_posted_by_user_id);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}